package cn.zn.user.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.zn.user.entity.SysUserJz;
import cn.zn.user.mapper.SysUserJzMapper;
import cn.zn.user.service.SysUserJzService;
import cn.zn.user.vo.SysUserJzEditVo;
import cn.zn.user.vo.SysUserJzPageVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zn-admin
 * @since 2021-08-03
 */
@Service
public class SysUserJzServiceImpl extends ServiceImpl<SysUserJzMapper, SysUserJz> implements SysUserJzService {

    @Override
    public List<SysUserJz> selectUserJzList(SysUserJzPageVo vo) {
        return baseMapper.selectUserJzList(vo);
    }

    @Override
    @Transactional
    public void insertUserJz(SysUserJzEditVo vo) {
        baseMapper.deleteUserJz(vo.getUserCode(), vo.getOrgType());

        if (CollUtil.isNotEmpty(vo.getOrgIds())) {
            for (String orgId : vo.getOrgIds()) {
                SysUserJz userJz = new SysUserJz();
                userJz.setUserCode(vo.getUserCode());
                userJz.setOrgId(orgId);
                userJz.setOrgType(vo.getOrgType());
                userJz.insert();
            }
        }
    }

}
